import { watcher } from "@feng3d/watcher";
import { DodecahedronGeometry } from "../../thirdparty/three/imports";
import { BufferGeometry3D } from "../core/BufferGeometry3D";

export class DodecahedronGeometry3D extends BufferGeometry3D
{
    radius?: number;
    detail?: number;

    get _geometry()
    {
        if (!this.__geometry)
        {
            this.__geometry = new DodecahedronGeometry(this.radius, this.detail);
        }

        return this.__geometry;
    }
    declare protected __geometry: DodecahedronGeometry;

    constructor()
    {
        super();
        watcher.watchs(this as DodecahedronGeometry3D, ["radius", "detail"], this._invalidate, this);
    }

    destroy()
    {
        watcher.unwatchs(this as DodecahedronGeometry3D, ["radius", "detail"], this._invalidate, this);
    }

    static get(geometry: DodecahedronGeometry)
    {
        let geometry3D = this._map.get(geometry) as DodecahedronGeometry3D;
        if (!geometry3D)
        {
            geometry3D = new DodecahedronGeometry3D();
            geometry3D.__geometry = geometry;
            this._map.set(geometry, geometry3D);
        }

        return geometry3D;
    }
}
